<%@ page import="cn.ecut.User" %>
<%@ page import="java.util.*" %><%--
  Created by IntelliJ IDEA.
  User: lujiapeng
  Date: 2020/9/16
  Time: 9:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>foreach</title>
</head>

<body>
    <div>
        <h1>一个最基本的循环</h1>
        for( int i  = 0 ; i <=10 ; i++){
            System.out.println(i);
        }
        <c:forEach var="i" begin="0" end="10" step="1">
            ${i}
        </c:forEach>
    </div>
    <hr>
    <%
        User user = new User() ;
        user.setPassword("123123");
        user.setName("张三");

        User user2 = new User() ;
        user2.setName("lisi");
        user2.setPassword("456789");

        User user3 = new User() ;
        user3.setName("王五");
        user3.setPassword("456789");

        User user4 = new User() ;
        user4.setName("赵六");
        user4.setPassword("456789");

        List<User> list = new ArrayList<User>() ;
        list.add( user ) ;
        list.add( user2 ) ;
        list.add( user3 ) ;
        list.add( user4 ) ;

        // 将 集合存放在 一个区域中
        request.setAttribute("userList" , list );
    %>

    <div>
        <h1>一个最基本的foreach循环</h1>
        for( Object i : (java.util.List)request.getAttribute("userList") ){
            System.out.println( i ) ;
        }
        <c:forEach var="i" items="${userList}" varStatus="vs">
            ${i.name} , ${vs.index }
        </c:forEach>
        <hr>
        <c:forEach var="i" items="${userList}" varStatus="vs">
            <div>${vs.index } : ${vs.step} : ${vs.begin} : ${vs.current} : ${vs.first} : ${vs.last}</div>
        </c:forEach>
    </div>


    <div>
        <h1>迭代Map</h1>
        <%
            Map<String , Object> map = new HashMap<>() ;

            map.put("班级1" , "class01") ;
            map.put("班级2" , "class02") ;
            map.put("班级3" , "class03") ;
            map.put("班级4" , "class04") ;
            
            request.setAttribute("classMap" , map );

            Set<Map.Entry<String, Object>> entries = map.entrySet();
            for (Map.Entry<String, Object> e :
                    entries) {

            }
        %>
        
        <c:forEach items="${classMap.entrySet()}" var="e">
            <div>${e.key} : ${e.value}</div>
        </c:forEach>
    </div>
</body>
</html>
